package cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author fei
 * @date 2023/1/17 10:30
 * @description
 */
public class CASDemo {

    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(5);
        // compareAndSet：比较并交换，如果和期望值相等，就进行更新值
        System.out.println(atomicInteger.compareAndSet(5, 2022) + "\t" + atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(5, 2022) + "\t" + atomicInteger.get());
        atomicInteger.getAndIncrement();
    }

}
